<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>考勤规则新增面板</title>

</head>
<body>

	
	<style type="text/css">
.insert_bt_rules {
	background: #CDDEF4;
}

.edContent table {
	width: 100%;
	table-layout: fixed;
}

.edContent span.lb {
	display: inline-block;
	padding-left: 10px;
	width: 120px;
	line-height: 20px;
	height: 20px;
	text-align: left;
	color: rgb(0, 0, 0);
	padding-right: 5px;
	border-bottom: 1px solid rgb(204, 204, 204);
}
</style>
	<script type="text/javascript">
		$(function(){
			/* 返回 */
			$(".return_add").linkbutton({onClick:function(){
				$("#lxl-result-rules").panel({
					href : "to_checkingfindall"
				})
			}});
		});
			/* 添加 */
			var lyAddRules = function(){
				//考勤规则
			/* 	var checkingRuleId = $("#checkingRuleId").textbox('getValue'); */
				var checkingRuleid11 = $("#lxl_checkingRuleId").textbox('getText');
				var checkingRuleName11 = $("#lxl_checkingRuleName1").textbox('getText');
				var checkingRuleUp = $("#lxl_checkingRuleUp").val();
				var checkingRuleDown = $("#lxl_checkingRuleDown").val();
				
				var rules_checkingRuleKg = $("#lxl_rules_checkingRuleKg").val();
				var isChecked ;
				if($('#lxl_rules_checkingRuleKg').prop("checked")){
					isChecked=1;
				}else{
					isChecked=0;
				}
				//备注
				var remark = $("#lxl-checkingResult-remark").val();
				if($("#lxl_checkingRuleName1").textbox("getText")=="" || $("#attruNamecom2").textbox("getText")=="" ||
						$("#calculateRulecom4").textbox("getText")==""){
					$.messager.confirm("提示","请填写全部内容",function(r){
						
			""		});
				}else{
					$("<form method='post'>").appendTo(document.body).form({
						url: 'check_insert',
						onSubmit: function(params){
							//考勤规则
							/*  params["rule.checkingRuleId"] = checkingRuleId; */
							/*  params["kaoqinrules.kqruleId"] = checkingRuleid11; */
							 //alert("checkingRuleid11:编号"+checkingRuleid11);
							 params["kaoqinrules.kqruleName"] = checkingRuleName11;
							 params["kaoqinrules.kqruleUp"] = checkingRuleUp;
							 params["kaoqinrules.kqruleDown"] = checkingRuleDown;
							 params["kaoqinrules.kqruleKg"] = isChecked;
							 //alert(isChecked);
							 params["kaoqinrules.kqruleMarks"] = remark;
							//获取所有行（规则明细）
							var rows = $("#lxl-result-rules-dg").datagrid("getRows");
							for(var i = 0; i < rows.length; i ++){
								params["attruId"] = rows[i].ATTRU_ID;
								params["calcluateruleId"] = rows[i].CALCLUATERULE_ID;

							}
						},
						success:function(v){
							v = eval("(" + v + ")");
							if(v.success){
								$.messager.alert('恭喜', '添加成功');
								//重定向
								$('#lxl-result-rules').panel('open').panel('refresh','to_checkingfindall');
								
							}else{
								$.messager.alert('错误', '对不起，操作失败，原因：' + v.message);
							}
						}
					}).submit();
				}
				
				
			}
		
		
	</script>
	<div class="easyui-panel" id="lxl-result-rules" data-options="border:false,fit:true,toolear:'#lxl-insert_bt-rules'">
	
	<div id="lxl-insert_bt-rules" class="insert_bt_rules">
		<a href="JavaScript:lyAddRules()" class="easyui-linkbutton"
			data-options="text:'添加',iconCls:'icon-save',plain:true"></a>
		<a class="easyui-linkbutton return_add" iconCls="icon-reload" plain="true" title="返回"
			data-options="text:'返回'"></a> 
		<span style="float: right; font-size: 12px; margin: 5px;">新增：考勤规则</span>
	</div>
	
	<div style="margin: 5px; padding: 5px; border-bottom: 2px solid #2B91D5; width: 900px">概要</div>
		<table cellpadding="0" cellspacing="0"
			style="width: 1000px; table-layout: fixed; padding-left: 50px;">
			<tbody>

				<tr>
					<td style="width: 50%; vertical-align: top;">
						<div class="edContent">
							<table id="ct1" cellspacing="10" cellpadding="0" tag="A">
								<tbody>
									<tr>
										<td><span><em>*</em></span> <input class="easyui-textbox"
											id="lxl_checkingRuleId" name="checkingRuleId"
											data-options="label:'编号', width:280,labelWidth:60,readonly:true" 
											prompt="系统生成中……"
											"/></td>
									</tr>
									<tr>
										<td><span><em>*</em></span> <input class="easyui-textbox"
											id="lxl_checkingRuleName1" name="lxl_checkingRuleName"
											data-options="label:'名称', width:280,labelWidth:60,required:true" />
										</td>
									</tr>
									<tr>
										<td><span>忽略旷工</span> <input id="lxl_rules_checkingRuleKg" type="checkbox"></td>
									</tr>
								</tbody>
							</table>
						</div>
					</td>

					<td style="width: 50%; vertical-align: top;">
						<div class="edContent">
							<table id="ct1" cellspacing="10" cellpadding="0" tag="A">
								<tbody>
									<tr>
										<td><select id="lxl_checkingRuleUp" class="easyui-combobox"
											data-options="label:
										'实出勤计算方式(上班)',width:300,labelWidth:140,panelHeight:'auto',
										editable:false"
											name="checkingRuleUp">
												<option value="按计划计算实出勤">按计划计算实出勤</option>
												<option value="按打卡计算实出勤">按打卡计算实出勤</option>
										</select></td>
									</tr>
									<tr>
										<td><select id="lxl_checkingRuleDown" class="easyui-combobox"
											data-options="label:'实出勤计算方式(下班)',width:300,labelWidth:140,panelHeight:'auto',editable:false"
											name="checkingRuleDown">
												<option value="按计划计算实出勤">按计划计算实出勤</option>
												<option value="按打卡计算实出勤">按打卡计算实出勤</option>
										</select></td>
									</tr>
									<tr>
										<td><span style="display: inline-block; , width: 120px">制单</span>
											<span id="current-time" class="lb" style="width: 165px;"></span>
										</td>
									</tr>
								</tbody>
							</table>
						</div>
					</td>
				</tr>

				<tr>
					<td colspan="3" style="width: 100%;">
				<tr>
			</tbody>
		</table>
		<script type="text/javascript">
			$(function() {
				setInterval(function() {
					var now = (new Date()).toLocaleString();
					$('#current-time').text(now);
				}, 1000);
			})
			
		</script>
		<div
			style="margin: 5px 5px 5px 15px; padding: 5px; border-bottom: 2px solid #2B91D5; width: 1000px">
			规则明细</div>
		
	    <div data-options="region:'north', bodyCls:'bodyCls',border:false" style="height:40px,margin-bottom:24px;">
	    	<table width="1000px" style="margin:5px 5px 5px 18px;">
	    		<tr>
	    			<!-- <td style="width: 25%"><input id="kqruleNamecom1" class="easyui-combobox"
						data-options="label:'规则名称',labelWidth:60,width:'80%',valueField:'KQRULE_ID',
						textField:'KQRULE_NAME',editable:false,panelHeight:'auto',url:'nopage_checkfindAll'"></td> -->
					<td style="width: 25%"><input id="attruNamecom2" class="easyui-combobox"
						data-options="label:'规则结果',labelWidth:100,width:'80%',valueField:'ATTRU_ID',
						textField:'ATTRU_NAME',editable:false,panelHeight:'auto',url:'nopage_findAllAttend'">
					</td>
					<td style="width: 25%"><input id="attruAffaircom3" class="easyui-combobox"
						data-options="label:'结果类别',labelWidth:100,width:'80%',valueField:'ATTRU_ID',
						textField:'ATTRU_AFFAIR',editable:false,panelHeight:'auto',url:'nopage_findAllAttend'"></td>
	    		</tr>
	    		<tr></tr>
	    		<tr>
	    			<td style="width:25%"><input id="calculateRulecom4" class="easyui-combobox"
						data-options="label:'计算规则',labelWidth:100,width:'80%',valueField:'CALCLUATERULE_ID',
						textField:'CALCLUATERULE_NAME',editable:false,panelHeight:'auto',url:'nopage_findAllCalcluaterule'"></td>
	    			<td style="width:25%"><input id="calculateCountcom5" class="easyui-combobox"
						data-options="label:'一天工作小时数',labelWidth:100,width:'80%',valueField:'CALCLUATERULE_ID',
						textField:'CALCLUATERULE_COUNT',editable:false,panelHeight:'auto',url:'nopage_findAllCalcluaterule'"></td>
	    		</tr>
	    	</table>
	    </div>   
		<div id="lxl-tb-rules-s" style="padding: 5px,margin: 5px">
			<a id="btn" href="JavaScript:lxlAddRulesDetail()" class="easyui-linkbutton"
				data-options="iconCls:'icon-add'">添加规则</a> <a id="btn" href="JavaScript:lxlDeleteRules()"
				class="easyui-linkbutton" data-options="iconCls:'icon-cancel'">删除规则</a>
			<a id="btn" href="JavaScript:lxlRemoveRules()" class="easyui-linkbutton"
				data-options="iconCls:'icon-search'">清空规则</a>
		</div>
		
		<script type="text/javascript">
			/* 添加规则 */
			var lxlAddRulesDetail = function(){
				//获取当前页的数据
				//规则名称
				//var kqruleNamecom1 = $("#kqruleNamecom1").combobox("getText");
				//规则结果
				var attruNamecom2 = $("#attruNamecom2").combobox("getText");
				var attruNamecom2id = $("#attruNamecom2").combobox("getValue");
				//结果类别
				var attruAffaircom3 = $("#attruAffaircom3").combobox("getText");
				//计算规则
				var calculateRulecom4 = $("#calculateRulecom4").combobox("getText");
				var calculateRulecom4id = $("#calculateRulecom4").combobox("getValue");
				//一天工作几小时
				var calculateCountcom5 = $("#calculateCountcom5").combobox("getText");
			    $('#lxl-result-rules-dg').datagrid("insertRow", {//这里还有一个index参数，可指定添加到某行。如果不写，默认为在最后一行添加
				    row: {
					  	// KQRULE_NAME:kqruleNamecom1,
					  	 ATTRU_NAME:attruNamecom2,
					  	 ATTRU_AFFAIR:attruAffaircom3,
					  	 CALCLUATERULE_NAME:calculateRulecom4,
					  	 CALCLUATERULE_COUNT:calculateCountcom5,
					  	 ATTRU_ID:attruNamecom2id,
					  	 CALCLUATERULE_ID:calculateRulecom4id
	                }                  
				});
			}
			
			/* 删除规则 */
			var lxlDeleteRules = function(){
				//获取要选中的行
				var row = $("#lxl-result-rules-dg").datagrid("getSelected");
				if(!row){
					$.messager.alert('提示', '没有选中要删除的行！');
					return;
				}
				$.messager.confirm('确认', '真的要删除吗？', function(v){
					if(v){
						//找到行对应的索引
						var rowIndex = $("#lxl-result-rules-dg").datagrid("getRowIndex", row);
						//删除行
						 $("#lxl-result-rules-dg").datagrid("deleteRow", rowIndex);
					}
				});
			}
			/* 清空规则 */
			var lxlRemoveRules = function(){
				$.messager.confirm('警告','你确定要清空所有规则吗？',function(v){
					if(v){
						//获取所有的行
						var rows = $("#lxl-result-rules-dg").datagrid("getRows");
						//循环遍历 一行行删除
						for(var i = rows.length - 1; i >= 0; i --){
							$("#lxl-result-rules-dg").datagrid("deleteRow", i);
						}
					}
				})
				
			}
		</script>
		<div style="margin:5px 5px 5px 18px;">
			<table id="lxl-result-rules-dg" class="easyui-datagrid" width="80%" style="min-height:100px"
				data-options="
				rownumbers:true,
	        	fitColumns:true,
	        	singleSelect:true,
	        	border:false,
	        	toolbar: '#lxl-tb-rules-s'
	        ">
				<thead>
					<tr>
						<!-- <th width="10%" data-options="field:'KQRULE_ID',align:'center'">规则编号</th> -->
						<!-- <th width="20%"  data-options="field:'KQRULE_NAME',align:'center'">规则名称</th> -->
						<th width="20%"  data-options="field:'ATTRU_NAME',align:'center'">规则结果</th>
						<th width="20%"  data-options="field:'ATTRU_AFFAIR',align:'center'">结果类别</th>
						<th width="20%"  data-options="field:'CALCLUATERULE_NAME',align:'center'">计算规则</th>
						<th width="20%"  data-options="field:'CALCLUATERULE_COUNT',align:'center'">一天工作小时数</th>
					</tr>
				</thead>
				
			</table>
		</div>
		<div
			style="margin: 5px 5px 5px 15px; padding: 5px; border-bottom: 2px solid #2B91D5; width: 1000px">
			其他
		</div>
		<div style="margin: 5px">
		<input class="easyui-textbox"
			id="lxl-checkingResult-remark"
			data-options="width:900,height:100,multiline:true" />
		</div>
	</div>
	
</body>
</html>